<<<<<<< HEAD
import datetime
import time
import inspect
from functools import wraps


def main():
    test1()
    print("".center(26, "-"))
    test2(1.5)
    print("".center(26, "-"))


def decorator(second: int = 5):
    def _decorator(function):
        @wraps(function)
        def in_decorator(*args, **kwargs):
            if isinstance(second, (int, float)):
                print("函数开始".center(23, "-"))
                print("{}运行中……".format(in_decorator.__name__))
                start = datetime.datetime.now()
                result = function(*args, **kwargs)
                end = datetime.datetime.now()
                print("函数结束".center(23, "-"))
                t = (end - start).total_seconds()
                print("函数:{},用时：{}".format(in_decorator.__name__, t), end=" ")
                if t > second:
                    print("超出预计时间{}s".format(second))
                else:
                    print()
                return result
            else:
                raise TypeError("second类型错误.{}".format(inspect.signature(decorator).parameters["second"]))

        return in_decorator

    return _decorator


@decorator(1)  # test1=decorator(test1)
def test1():
    time.sleep(0.5)


@decorator(1)  # test1=decorator(test1)
def test2(t):
    time.sleep(t)


if __name__ == '__main__':
    main()
=======
import datetime
import time
import inspect
from functools import wraps


def main():
    test1()
    print("".center(26, "-"))
    test2(1.5)
    print("".center(26, "-"))


def decorator(second: int = 5):
    def _decorator(function):
        @wraps(function)
        def in_decorator(*args, **kwargs):
            if isinstance(second, (int, float)):
                print("函数开始".center(23, "-"))
                print("{}运行中……".format(in_decorator.__name__))
                start = datetime.datetime.now()
                result = function(*args, **kwargs)
                end = datetime.datetime.now()
                print("函数结束".center(23, "-"))
                t = (end - start).total_seconds()
                print("函数:{},用时：{}".format(in_decorator.__name__, t), end=" ")
                if t > second:
                    print("超出预计时间{}s".format(second))
                else:
                    print()
                return result
            else:
                raise TypeError("second类型错误.{}".format(inspect.signature(decorator).parameters["second"]))

        return in_decorator

    return _decorator


@decorator(1)  # test1=decorator(test1)
def test1():
    time.sleep(0.5)


@decorator(1)  # test1=decorator(test1)
def test2(t):
    time.sleep(t)


if __name__ == '__main__':
    main()
>>>>>>> 68ab0663441d97a28925d675f644e9553bc1b45c
